package com.example.myapplication;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;


public class TextViewActivity extends AppCompatActivity {

    private NotificationManager notificationManager;

    private Notification notification;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text_view);

        //中划线
        TextView textView4 = findViewById(R.id.textview_4);
        textView4.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        textView4.getPaint().setAntiAlias(true);   // 去锯齿

        //下划线
        TextView textView5 = findViewById(R.id.textview_5);
        textView5.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

        //html形式实现插入文字
        TextView textView6 = findViewById(R.id.textview_6);
        textView6.setText(Html.fromHtml("<u>12345</u>", 1));  //html形式实现插入文字


        //通知

        //获取通知管理器
        notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        //8.0以上版本可为每种通知类型创建渠道，并设置重要度（这段不写也行，还不知道啥用）
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel notificationChannel = new NotificationChannel("sun", "test", NotificationManager.IMPORTANCE_HIGH);
            notificationManager.createNotificationChannel(notificationChannel);
        }

        //创建意图，将目标activity放入意图
        Intent intent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

        //通知主体
        notification = new NotificationCompat.Builder(this, "sun")
                .setContentTitle("狗狗来了！")
                .setContentText("一只名为“飞机”的柯基宝宝出现了！")
                .setSmallIcon(R.drawable.ic_baseline_airplanemode_active_24)
                .setContentIntent(pendingIntent)
                .setAutoCancel(true)
                .build();

        new Handler().postDelayed(() -> {
            MainActivity instance = MainActivity.instance;
            View viewById = instance.findViewById(R.id.image_corgi);
            viewById.setVisibility(View.VISIBLE);
            View viewById1 = instance.findViewById(R.id.progress_bar);
            viewById1.setVisibility(View.GONE);
            MainActivity.firstOpen = false;

            Log.e("进度条显示状态：", String.valueOf(viewById1.getVisibility()));

            notificationManager.notify(1, notification);
        }, 2000);


    }

}